/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, Hardware
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FOUNDATION_GRAPHIC_3D_STANDARD_RENDER_SERVICE_TEXTURE_LAYER_H_
#define FOUNDATION_GRAPHIC_3D_STANDARD_RENDER_SERVICE_TEXTURE_LAYER_H_

#include <cstdint>
#include <functional>
#include <future>
#include <shared_mutex>

#include "engine_service.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkDrawable.h"
#include "include/core/SkImage.h"

namespace OHOS {
namespace Render3D {
struct TextureImage {
    explicit TextureImage(const TextureInfo& info) : textureInfo_(info) {}
    TextureImage() = default;

    TextureInfo textureInfo_;
    std::function<EngineService::EngineTask> task_ = nullptr;
    std::shared_future<void> ftr_;
    std::promise<void> pms_;
    sk_sp<SkImage> skImage_;
};


class TextureLayer : public SkDrawable {
public:
    TextureLayer() : image_(TextureImage()) {}
    virtual ~TextureLayer();
    virtual SkRect onGetBounds() override;
    virtual void onDraw(SkCanvas* canvas) override;
    void UpdateAsyncTexImage(std::shared_future<void> ftr, const TextureInfo info, int32_t offsetX, int32_t offsetY);
    std::shared_future<void> UpdateSyncTexImage(const std::function<EngineService::EngineTask>& task);
private:
    void DrawTexture(SkCanvas* canvas);
    TextureImage image_;
    int32_t offsetX_;
    int32_t offsetY_;
    std::mutex ftrMut_;
};
} // namespace OHOS
} // namespace Render3D
#endif